const WebSocket = require('ws')

const wss = new WebSocket.WebSocketServer({ port: 9527 });

wss.on('connection', (ws) => {
  ws.on('open', () => {
    console.log('connected');
    ws.send(Date.now());
  });

  ws.on('message', (data, isBinary) => {
    wss.clients.forEach(function each(client) {
      if (client.readyState === WebSocket.OPEN) {
        console.log('data.toString()', data.toString());
        console.log('isBinary', isBinary);
        client.send(data.toString(), { isBinary });
      }
    });
  });

  ws.on('close', () => {
    console.log('disconnected');
  });
});
